﻿/*
 
    This file is part of AnkhBG. aaaa

    AnkhBG is free software: you can redistribute it and/or modify
    it under the terms of the GNU Lesser General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    AnkhBG is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public License
    along with AnkhBG.  If not, see <http://www.gnu.org/licenses/>.
 
 */
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace AnkhBG
{
    public partial class ConfigForm : Form
    {
        public Settings settings = Settings.Instance;
        public OpenFileDialog opendialog = new OpenFileDialog();

        public ConfigForm()
        {
            InitializeComponent();
            GetSettings();
        }
        public void GetSettings()
        {
            textBox1.Text = settings.AVTaskDir;
            textBox2.Text = settings.WGTaskDir;
            textBox3.Text = settings.ABTaskDir;
            textBox4.Text = settings.EoTSTaskDir;
            comboBox2.Text = settings.QueueBG;

            if (settings.QueueType == "specific")
                radioButton3.Checked = true;
            else
                radioButton1.Checked = true;

            if (settings.UseProfiles == "true")
                radioButton4.Checked = true;
            else
                radioButton2.Checked = true;

            if (settings.PatherDeaths == "true")
                checkBox3.Checked = true;

            if (settings.JoinAfter != "-1" && settings.JoinAfter != "")
            {
                numericUpDown1.Text = settings.JoinAfter;
                nudJoinAfterRandom.Value = settings.JoinAfterRandom;
                checkBox4.Checked = true;
            }
            else
            {
                numericUpDown1.Text = "30";
                nudJoinAfterRandom.Value = settings.JoinAfterRandom;
                checkBox4.Checked = false;
            }

            if (settings.RandomTitles == "true")
                checkBox1.Checked = true;

            if (settings.GliderTimer != "-1" && settings.GliderTimer != "")
            {
                numericUpDown_GliderTimer.Text = settings.GliderTimer;
                checkBox_GlideTimer.Checked = true;
            }

            if (settings.BeginDelay != "-1" && settings.BeginDelay != "")
            {
                begindelayNumericUpdown.Text = settings.BeginDelay;
                begindelayCheckbox.Checked = true;
            }

            if (settings.DontWait == "true")
            {
                dontwaitCheckbox.Checked = true;
            }

            cbTaskbarHide.Checked = settings.TaskbarHide;

            if (settings.MaxMarks != "-1" && settings.MaxMarks != "")
            {
                numericUpDownMaxMarks.Text = settings.MaxMarks;
                checkBoxMarkCounter.Checked = true;
                if (settings.MaxMarksBG != "" && settings.MaxMarksBG != "none")
                {
                    if (settings.MaxMarksBG == "AV")
                        radioButtonMaxMarks_AV.Checked = true;
                    else if (settings.MaxMarksBG == "AB")
                        radioButtonMaxMarks_AB.Checked = true;
                    else if (settings.MaxMarksBG == "WSG")
                        radioButtonMaxMarks_WSG.Checked = true;
                    else if (settings.MaxMarksBG == "EOTS")
                        radioButtonMaxMarks_EOTS.Checked = true;
                }
            }
        } 
        private void radioButton1_CheckedChanged(object sender, EventArgs e)
        {
            if (radioButton1.Checked)
            {
                this.comboBox2.Enabled = false;
                settings.QueueType = "closest";
            }
        }
        private void radioButton3_CheckedChanged(object sender, EventArgs e)
        {
            if (radioButton3.Checked)
            {
                this.comboBox2.Enabled = true;
                settings.QueueType = "specific";
                settings.QueueBG = comboBox2.Text;
            }
        }
        private void textBox1_MouseClick(object sender, MouseEventArgs e)
        {
            opendialog.Filter = "Group Profiles (*.xml)|*.xml";
            if (opendialog.ShowDialog() == DialogResult.OK)
            {
                Environment.CurrentDirectory = Main.path;

                settings.AVTaskDir = opendialog.FileName;
                textBox1.Text = opendialog.FileName;
            }
        }
        private void textBox2_MouseClick(object sender, MouseEventArgs e)
        {
            opendialog.Filter = "Group Profiles (*.xml)|*.xml";
            if (opendialog.ShowDialog() == DialogResult.OK)
            {
                Environment.CurrentDirectory = Main.path;

                settings.WGTaskDir = opendialog.FileName;
                textBox2.Text = opendialog.FileName;
            }
        }

        private void textBox3_MouseClick(object sender, MouseEventArgs e)
        {
            opendialog.Filter = "Group Profiles (*.xml)|*.xml";
            if (opendialog.ShowDialog() == DialogResult.OK)
            {
                Environment.CurrentDirectory = Main.path;

                settings.ABTaskDir = opendialog.FileName;
                textBox3.Text = opendialog.FileName;
            }
        }

        private void textBox4_MouseClick(object sender, MouseEventArgs e)
        {
            opendialog.Filter = "Group Profiles (*.xml)|*.xml";
            if (opendialog.ShowDialog() == DialogResult.OK)
            {
                Environment.CurrentDirectory = Main.path;

                settings.EoTSTaskDir = opendialog.FileName;
                textBox4.Text = opendialog.FileName;
            }
        }

        private void button3_MouseClick(object sender, MouseEventArgs e)
        {
            Close();
        }

        private void radioButton2_CheckedChanged(object sender, EventArgs e)
        {
            settings.UseProfiles = "false";
            textBox1.Enabled = false;
            textBox2.Enabled = false;
            textBox3.Enabled = false;
            textBox4.Enabled = false;
        }

        private void radioButton4_CheckedChanged(object sender, EventArgs e)
        {
            settings.UseProfiles = "true";
            textBox1.Enabled = true;
            textBox2.Enabled = true;
            textBox3.Enabled = true;
            textBox4.Enabled = true;
        }

        private void checkBox3_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBox3.Checked)
                settings.PatherDeaths = "true";
            else
                settings.PatherDeaths = "false";
        }

        private void checkBox4_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBox4.Checked)
            {
                settings.JoinAfter = numericUpDown1.Value.ToString();
                settings.JoinAfterRandom = Convert.ToInt32(nudJoinAfterRandom.Value);
            }
            else
            {
                settings.JoinAfter = "-1";
                settings.JoinAfterRandom = -1;
            }
        }

        private void numericUpDown1_ValueChanged(object sender, EventArgs e)
        {
            if (checkBox4.Checked)
                settings.JoinAfter = numericUpDown1.Value.ToString();
        }

        private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (radioButton3.Checked)
                settings.QueueBG = comboBox2.SelectedItem.ToString();
        }

        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBox1.Checked)
                settings.RandomTitles = "true";
            else
                settings.RandomTitles = "false";
        }

        private void checkBox_GlideTimer_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBox_GlideTimer.Checked)
                settings.GliderTimer = numericUpDown_GliderTimer.Value.ToString();
            else
                settings.GliderTimer = "-1";
        }

        private void numericUpDown_GliderTimer_ValueChanged(object sender, EventArgs e)
        {
            if (checkBox_GlideTimer.Checked)
                settings.GliderTimer = numericUpDown_GliderTimer.Value.ToString();
        }

        private void begindelayCheckbox_CheckedChanged(object sender, EventArgs e)
        {
            if (begindelayCheckbox.Checked)
                settings.BeginDelay = begindelayNumericUpdown.Value.ToString();
            else
                settings.BeginDelay = "-1";
        }

        private void begindelayNumericUpdown_ValueChanged(object sender, EventArgs e)
        {
            if (begindelayCheckbox.Checked)
                settings.BeginDelay = begindelayNumericUpdown.Value.ToString();
        }

        private void dontwaitCheckbox_CheckedChanged(object sender, EventArgs e)
        {
            if (dontwaitCheckbox.Checked)
                settings.DontWait = "true";
            else
                settings.DontWait = "false";
        }

        private void checkBoxMarkCounter_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBoxMarkCounter.Checked)
                settings.MaxMarks = numericUpDownMaxMarks.Value.ToString();
            else
                settings.MaxMarks = "-1";
        }

        private void numericUpDownMaxMarks_ValueChanged(object sender, EventArgs e)
        {
            if (checkBoxMarkCounter.Checked)
                settings.MaxMarks = numericUpDownMaxMarks.Value.ToString();
        }

        private void radioButtonMaxMarks_AV_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBoxMarkCounter.Checked)
                settings.MaxMarksBG = "AV";
        }

        private void radioButtonMaxMarks_AB_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBoxMarkCounter.Checked)
                settings.MaxMarksBG = "AB";
        }

        private void radioButtonMaxMarks_WSG_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBoxMarkCounter.Checked)
                settings.MaxMarksBG = "WSG";
        }

        private void radioButtonMaxMarks_EOTS_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBoxMarkCounter.Checked)
                settings.MaxMarksBG = "EOTS";
        }

        private void cbTaskbarHide_CheckedChanged(object sender, EventArgs e)
        {
            settings.TaskbarHide = (sender as CheckBox).Checked;
        }

        private void ConfigForm_Load(object sender, EventArgs e)
        {
            this.ShowInTaskbar = !settings.TaskbarHide;
        }
    }
}
